//
//  KUIModule.h
//  MengLiao
//
//  Created by xiuxin on 2022/7/15.
//  Copyright © 2022 ZHBen. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "KDataDrivenProtocol.h"
#import "KMStorage.h"
#import "KMvalue.h"
#import "KMView.h"
#import "KDDModel.h"

@protocol KMSelectEventHandler

- (void)didSelectModel:(__kindof NSObject *)model viewID:(NSString *)viewID spec:(NSString *)spec position:(KDDPosition *)position;

@end

@class KMContext;
@interface KUIModule : NSObject

@property (readonly,weak,nonatomic) KMContext * context;

@property (readonly,nonatomic) NSInteger index;
// storage 使用kvc 禁止修改或删除该属性！
@property (readonly,strong,nonatomic) KMStorage * storage;

@property (readonly,strong,nonatomic) NSArray<KDDSectionData *> * data;

@property (strong,nonatomic) NSMutableArray<KUIModule *> * moduleList;

@property (strong,nonatomic) KMValue * viewIDValue;

@property (strong,nonatomic) KMValue * viewTypeValue;

@property (strong,nonatomic) KMValue * decorationIDValue;

- (instancetype)initWithStorage:(KMStorage *)storage;

- (void)loadModelList:(NSArray *)modelList;

- (void)loadSectionList:(NSArray<KDDSectionData *> *)sectionList;

- (void)configSection:(KDDSectionData *)sectionData;

- (BOOL)configModel:(NSObject *)model;
// 指定特定代理 不设置则代理默认为module本身
- (void)appointDelegate:(id)delegate forViewIDList:(NSArray<NSString *> *)viewIDList;
// 获取指定的代理
- (id)appointedDelegateForViewID:(NSString *)viewID;

- (__kindof UIView<KMView> *)viewOfModel:(NSObject *)model;

- (NSArray *)visibleModels:(NSArray<__kindof UIView<KMView> *> **)visibleViews;

- (void)insertModuleList:(NSArray<KUIModule *> *)moduleList atIndexes:(NSIndexSet *)indexSet;

- (void)deleteModuleListAtIndexes:(NSIndexSet *)indexSet;

- (void)modifyModuleList:(NSArray<KUIModule *> *)moduleList atIndexes:(NSIndexSet *)indexSet;

- (void)reloadModuleList:(NSArray<KUIModule *> *)moduleList;

- (BOOL)hasModel;

@end
